package com.core.multithreading.a;

import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Sunil
 */
public class Producer extends Thread {

    List<String> jobs;

    public Producer(List<String> jobs) {
        this.jobs = jobs;
    }

    public void run() {
        for (int count = 0;; count++) {
            synchronized (jobs) {
                String s = "ELEMENT : " + count;
                jobs.add(s);
                System.out.println("P : ADDING   : " + s);
                jobs.notifyAll();
            }
            try {
                Thread.sleep(400);
            } catch (InterruptedException ex) {
                Logger.getLogger(Producer.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}
